package cn.tedu.ivos2.vehicle.controller;

import cn.tedu.ivos2.base.response.JsonResult;
import cn.tedu.ivos2.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos2.vehicle.pojo.dto.VehicleSaveDTO;
import cn.tedu.ivos2.vehicle.pojo.entity.Vehicle;
import cn.tedu.ivos2.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos2.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/vehicle/")
@Slf4j
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery){
        log.debug("车辆_查询参数:{}",vehicleQuery);
        List<VehicleVO>vehicleList=vehicleService.queryVehicle(vehicleQuery);
        log.debug("车辆_查询回显数据:{}",vehicleList);
        return JsonResult.ok(vehicleList);
    }

    @PostMapping("insertVehicle")
    public JsonResult insertVehicle(VehicleSaveDTO vehicleSaveDTO){
        log.debug("车辆_新增车辆数据:{}",vehicleSaveDTO);
        vehicleService.save(vehicleSaveDTO);
        return JsonResult.ok();
    }
    @DeleteMapping("delVehicle/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.debug("车辆_删除的车辆id:{}",id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @PostMapping("unbind/{id}")
    public JsonResult unBindVelFromGeo( @PathVariable Long id){
        log.debug("车辆_解绑车辆id:{}",id);
        vehicleService.unbind(id);
        return JsonResult.ok();
    }
    @PostMapping("bind/{geoId}/{id}")
    public JsonResult BindVelFromGeo( @PathVariable Long geoId,@PathVariable Long id){
        log.debug("车辆_绑定围栏id:{},车辆id:{}",geoId,id);
        vehicleService.bind(geoId,id);
        return JsonResult.ok();
    }

}
